package com.system.service.impl;

import com.system.mapper.AdminMapper;
import com.system.pojo.administrator;
import com.system.service.AdminService;
import com.system.utils.Md5Util;
import com.system.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Map;

@Service
public class AdminServiceImpl implements AdminService {
    @Autowired
    private AdminMapper adminMapper;
    @Override
    public administrator findByAdminAccount(String account) {
        administrator a = adminMapper.findByAdminAccount(account);
        return a;
    }

    @Override
    public void register(String name,String account, String password) {
        String md5String= Md5Util.getMD5String(password);
        adminMapper.add(name,account,md5String);
    }

    @Override
    public void update(String name) {
        Map<String,Object> map = ThreadLocalUtil.get();
        Integer id= (Integer) map.get("id");
        adminMapper.update(name,id);
    }

    @Override
    public void updatePwd(String newPwd) {
        Map<String,Object> map = ThreadLocalUtil.get();
        Integer id= (Integer) map.get("id");
        adminMapper.updatePwd(Md5Util.getMD5String(newPwd),id);
    }
}
